package com.shortLinked.project.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.shortLinked.project.common.constant.ColoredOutput.RED;
import static com.shortLinked.project.common.constant.ColoredOutput.RESET;

/**
 * mp 分页插件
 */
@Configuration
public class DataBaseConfiguration {
    /**
     * 分页插件
     * ConditionalOnMissingBean 条件注解 bean - 未存在就注入
     */
    @Bean
    @ConditionalOnMissingBean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        System.out.println(RED+"这里是:mybatisPlusInterceptor"+RESET);
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
